<template>
	<view>
		<view>
			<u-tabs-swiper bg-color="#fff" ref="uTabs" :bar-width="160" :bar-height="70"
			:bar-style="{background:'#20cbd4'}" active-color="#fff" inactive-color="#20cbd4"
			:list="list" :current="current" @change="tabsChange" :is-scroll="false"></u-tabs-swiper>
		</view>
		<swiper class="swiper" :current="swiperCurrent" @transition="transition" @animationfinish="animationfinish" @change="handleSwperChange">
			<swiper-item>
				<scroll-view class="swiper" scroll-y>
				<empty v-if="isEmpty&&isShow" :emptyImg="emptyImg" :emptyTxt="emptyTxt"></empty>
				<block v-if="!isEmpty&&isShow" v-for="(item, index) in seckillList">
				<view class="time">{{item.end_time}}秒杀结束</view>
				<view class="swiper-item" v-for="(item1, index1) in item.goods" @click="jumpPage(item1.id)">
					<view class="goodsImg"><image :src="item1.image_first"></image></view>
					<view class="goodsInfo">
						<view class="goodsTit u-line-1">{{item1.goods_name}}</view>
						<view class="remark u-line-1">{{item1.brief}}</view>
						<view style="margin-bottom: 20rpx;">
							<u-line-progress style="width: 290rpx;" height="20" :show-percent="false" :striped="true" :striped-active="true" active-color="#20cbd4" :percent="item1.percentage"></u-line-progress>
							<text style="margin-left:10rpx;font-size: 25rpx;color: #909399;">已秒杀{{item1.percentage}}%</text>
						</view>
						<view class="footer">
							<view class="price_box">
								<text style="font-size: 32rpx;margin-right: 10rpx;color: #FA3534;">
									¥{{item1.price}}
								</text>
								<text style="color: #909399;text-decoration: line-through;">
									¥{{item1.line_price}}
								</text>
							</view>
							<u-button :disabled="true" size="medium" :custom-style="overStyle" hover-class="none" shape="circle" plain>已结束</u-button>
						</view>
					</view>
				</view>
				</block>
				<u-loadmore :status="status" color="#909399" :margin-top="20" :margin-bottom="20" v-if="!isEmpty"/>
				</scroll-view>
			</swiper-item>
			<swiper-item>
				<scroll-view class="swiper" scroll-y>
				<empty v-if="isEmpty&&isShow" :emptyImg="emptyImg" :emptyTxt="emptyTxt"></empty>
				<block v-if="!isEmpty&&isShow" v-for="(item, index) in seckillList">
				<view class="time">仅剩<u-count-down color="#20cbd4" separator-color="#20cbd4" bg-color="#f6f6f6" :timestamp="item.have_time"></u-count-down>秒杀结束</view>
				<view class="swiper-item" v-for="(item1, index1) in item.goods" @click="jumpPage(item1.id)">
					<view class="goodsImg"><image :src="item1.image_first"></image></view>
					<view class="goodsInfo">
						<view class="goodsTit u-line-1">{{item1.goods_name}}</view>
						<view class="remark u-line-1">{{item1.brief}}</view>
						<view style="margin-bottom: 20rpx;">
							<u-line-progress style="width: 290rpx;" height="20" :show-percent="false" :striped="true" :striped-active="true" active-color="#20cbd4" :percent="item1.percentage"></u-line-progress>
							<text style="margin-left:10rpx;font-size: 25rpx;color: #909399;">已秒杀{{item1.percentage}}%</text>
						</view>
						<view class="footer">
							<view class="price_box">
								<text style="font-size: 32rpx;margin-right: 10rpx;color: #FA3534;">
									¥{{item1.price}}
								</text>
								<text style="color: #909399;text-decoration: line-through;">
									¥{{item1.line_price}}
								</text>
							</view>
							<u-button @click="jumpPage(item1.id)" size="medium" :custom-style="confrimStyle" hover-class="none" shape="circle" plain>立即秒杀</u-button>
						</view>
						
					</view>
				</view>
				</block>
				<u-loadmore :status="status" color="#909399" :margin-top="20" :margin-bottom="20" v-if="!isEmpty"/>
				</scroll-view>
			</swiper-item>
			<swiper-item>
				<scroll-view class="swiper" scroll-y>
				<empty v-if="isEmpty&&isShow" :emptyImg="emptyImg" :emptyTxt="emptyTxt"></empty>
				<block v-if="!isEmpty&&isShow" v-for="(item, index) in seckillList">
				<view class="time">{{item.start_time}}秒杀开始</view>
				<view class="swiper-item" v-for="(item1, index1) in item.goods" @click="jumpPage(item1.id)">
					<view class="goodsImg"><image :src="item1.image_first"></image></view>
					<view class="goodsInfo">
						<view class="goodsTit u-line-1">{{item1.goods_name}}</view>
						<view class="remark u-line-1">{{item1.brief}}</view>
						<view style="margin-bottom: 20rpx;">
							<u-line-progress style="width: 290rpx;" height="20" :show-percent="false" :striped="true" :striped-active="true" active-color="#ECBD6F" :percent="item1.percentage"></u-line-progress>
							<text style="margin-left:10rpx;font-size: 25rpx;color: #909399;">已秒杀{{item1.percentage}}%</text>
						</view>
						<view class="footer">
							<view class="price_box">
								<text style="font-size: 32rpx;margin-right: 10rpx;color: #FA3534;">
									¥{{item1.price}}
								</text>
								<text style="color: #909399;text-decoration: line-through;">
									¥{{item1.line_price}}
								</text>
							</view>
							<u-button :disabled="true" size="medium" :custom-style="overStyle" hover-class="none" shape="circle" plain>还未开始</u-button>
						</view>
					</view>
				</view>
				</block>
				<u-loadmore :status="status" color="#909399" :margin-top="20" :margin-bottom="20" v-if="!isEmpty"/>
				</scroll-view>
			</swiper-item>
		</swiper>
		<login-model ref="loginModel"></login-model>
		<hoverMenu></hoverMenu>
	</view>
</template>

<script>
	import loginModel from "@/components/public/loginModel.vue";
	import empty from "@/components/public/empty.vue";
	import hoverMenu from "@/components/public/sa-hover-menu.vue";
	import {timeLimitedList} from "@/common/api.js";
	export default {
		components: {
			loginModel,
			empty,
			hoverMenu
		},
		data() {
			return {
				list: [{
					name: '已结束'
				}, {
					name: '进行中'
				}, {
					name: '即将开始'
				}],
				current: 1,
				swiperCurrent: 1,
				overStyle:{
					color:"#fff",
					border:"5rpx #fff",
					background:"#909399",
					padding:"0 40rpx"
				},
				confrimStyle:{
					color:"#fff",
					border:"5rpx #0e595d",
					background:"#20cbd4",
					padding:"0 40rpx"
				},
				seckillList:[],
				status: 'loadmore',
				pageSize: 10,
				pageStart: 1,
				total:0,
				isSearch:false,
				isShow:false,
				isEmpty:false,
				emptyImg:"https://yunxingzhan.oss-cn-hangzhou.aliyuncs.com/miniprogram/images/images/empty_goods.png",
				emptyTxt:"暂无秒杀活动",
			};
		},
		onLoad: function(options) {
			this.isShow = false;
			this.seckillList=[];
			this.pageStart = 1;
			this.selectSeckillList();
		},
		onReachBottom: function() {
			if(this.total/(this.pageStart*this.pageSize)>1){
				this.pageStart++;
				this.selectSeckillList();
			}else{
				this.status = 'nomore';
			}
		},
		methods: {
			floatTouchClick(index){
				this.$uniApi.floatTouch(index);
			},
			selectSeckillList(){
				timeLimitedList(this,{page:this.pageStart,limit:this.pageSize,type:this.swiperCurrent});
			},
			tabsChange(index) {
				this.swiperCurrent = index;
			},
			transition(e) {
				let dx = e.detail.dx;
				this.$refs.uTabs.setDx(dx);
			},
			animationfinish(e) {
				let current = e.detail.current;
				this.$refs.uTabs.setFinishCurrent(current);
				this.swiperCurrent = current;
				this.current = current;
				if(this.isSearch){
					//每次切换时重新查询数据
					this.status = 'loadmore';
					this.isEmpty = false;
					this.seckillList=[];
					this.pageStart = 1;
					this.selectSeckillList();
				}
			},
			handleSwperChange(){
				this.isSearch = true;
			},
			jumpPage(id){
				uni.navigateTo({
				  url: '/seckill/goodsDetail?id='+id
				});
			}
		}
	};
</script>
<style >
	page{
		font-family: PingFang SC;
		background: #f6f6f6;
	}
	.swiper{
		height: calc(100vh - var(--window-top));
	}
	.time{
		margin: 10rpx 20rpx;
		font-size: 25rpx;
		color: #909399;
	}
	.swiper-item{
		margin-top: 20rpx;
		padding: 20rpx;
		background-color: #fff;
		display: flex;
		border-bottom: 0.5rpx solid #e4e7ed;
	}
	.goodsImg{
		width: 220rpx;
		height: 220rpx;
	}
	.goodsImg image{
		width: 100%;
		height: 100%;
	}
	.goodsInfo{
		margin-left: 15rpx;
		width: 500rpx;
	}
	.goodsTit{
		font-size: 32rpx;
		margin-bottom: 10rpx;
	}
	.remark{
		color: #0e595d;
	}
	.footer{
		display: flex;
		justify-content: space-between;
		align-items: flex-end;
	}
</style>

